<table width="100%"><tr><td width="20%">
<a href="../index.html">&lt; index</a><br />
<a href="index.html">&lt; 2. Console emulator</a><br />
<a href="console_init.html">&lt; 2.1 Initializing the console</a>
</td><td width="60%">
<p align="center">
=====================================<br />
2.1.2 Using a custom bitmap font<br />
=====================================<br />
</p></td><td width="20%">
</td></tr></table>
<style type="text/css">
.code { color:#444444; background-color:#EEEEEE;}
pre { color:#444444; background-color:#EEEEEE;}
table.param td { border : 1px solid #000000; }
th { background-color: #44BBFF; color: #FFFFFF }
table.none td { border : 0 }
</style>
This function allows you to use a bitmap font (png or bmp) with custom character size or layout.<br />
<b>It should be called before initializing the root console with <a href="console_init_root.html">initRoot</a>.</b><br />
Once this function is called, you can define your own custom mappings using <a href="console_map.html">mapping functions</a><br />
<p class="code"><pre>
C++ : static void TCODConsole::setCustomFont(const char *fontFile, int flags=TCOD_FONT_LAYOUT_ASCII_INCOL,int nbCharHoriz=0, int nbCharVertic=0)
C   : void TCOD_console_set_custom_font(const char *fontFile, int flags,int nb_char_horiz, int nb_char_vertic)
Py  : console_set_custom_font(fontFile, flags=FONT_LAYOUT_ASCII_INCOL,nb_char_horiz=0, nb_char_vertic=0)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>fontFile</td><td>Name of a .bmp or .png file containing the font.</td></tr>
<tr><td>flags</td><td>Used to define the characters layout in the bitmap and the font type :<br />
TCOD_FONT_LAYOUT_ASCII_INCOL : characters in ASCII order, code 0-15 in the first column<br />
TCOD_FONT_LAYOUT_ASCII_INROW : characters in ASCII order, code 0-15 in the first row<br />
TCOD_FONT_LAYOUT_TCOD : simplified layout. See examples below.<br />
TCOD_FONT_TYPE_GREYSCALE : create an anti-aliased font from a greyscale bitmap<br />
For python, remove TCOD _ :<br />
libtcod.FONT_LAYOUT_ASCII_INCOL
</td></tr>
<tr><td>nbCharHoriz,nbCharVertic</td><td>Number of characters in the font.<br />Should be 16x16 for ASCII layouts, 32x8 for TCOD layout.<br />But you can use any other layout.<br />If set to 0, there are deduced from the font layout flag.</td></tr>
</table>
<h4>Different font layouts</h4>
<table>
<tr><td>ASCII_INROW</td><td>ASCII_INCOL</td><td>TCOD</td></tr>
<tr><td><img src='terminal8x8_gs_ro.png' /></td><td><img src='terminal8x8_gs_as.png' /></td><td><img src='terminal8x8_gs_tc.png' /></td></tr>
</table>
<ul>
<li>ascii, in columns : characters 0 to 15 are in the first column. The space character is at coordinates 2,0.</li>
<li>ascii, in rows : characters 0 to 15 are in the first row. The space character is at coordinates 0,2.</li>
<li>tcod : special mapping. Not all ascii values are mapped. The space character is at coordinates 0,0.</li>
</ul>
<h4>Different font types</h4>
<table>
<tr><td>standard<br />(non antialiased)</td><td>antialiased<br />(32 bits PNG)</td><td>antialiased<br />(greyscale)</td></tr>
<tr><td><img src='terminal.png' /></td><td><img src='terminal8x8_aa_as.png' /></td><td><img src='terminal8x8_gs_as.png' /></td></tr>
</table>
<ul>
<li>standard : transparency is given by a key color automatically detected by looking at the color of the space character</li>
<li>32 bits : transparency is given by the png alpha layer. The font color does not matter</li>
<li>greyscale : transparency is given by the pixel value. You can use white characters on black background or black characters on white background. The background color is automatically detected by looking at the color of the space character</li>
</ul>
Example :<br />
Examples of fonts can be found in libtcod's fonts directory. Check the Readme file there.<br />
<p class="code"><pre>
C++ : TCODConsole::setCustomFont("standard_8x8_ascii_in_col_font.bmp",TCOD_FONT_LAYOUT_ASCII_INCOL);
      TCODConsole::setCustomFont("32bits_8x8_ascii_in_row_font.png",TCOD_FONT_LAYOUT_ASCII_INROW);
      TCODConsole::setCustomFont("greyscale_8x8_tcod_font.png",TCOD_FONT_LAYOUT_TCOD | TCOD_FONT_TYPE_GREYSCALE);
C   : TCOD_console_set_custom_font("standard_8x8_ascii_in_col_font.bmp",TCOD_FONT_LAYOUT_ASCII_INCOL,16,16);
      TCOD_console_set_custom_font("32bits_8x8_ascii_in_row_font.png",TCOD_FONT_LAYOUT_ASCII_INROW,32,8);
      TCOD_console_set_custom_font("greyscale_8x8_tcod_font.png",TCOD_FONT_LAYOUT_TCOD | TCOD_FONT_TYPE_GREYSCALE,32,8);
Py  : libtcod.console_set_custom_font("standard_8x8_ascii_in_col_font.bmp",libtcod.FONT_LAYOUT_ASCII_INCOL)
      libtcod.console_set_custom_font("32bits_8x8_ascii_in_row_font.png",libtcod.FONT_LAYOUT_ASCII_INROW)
      libtcod.console_set_custom_font("greyscale_8x8_tcod_font.png",libtcod.FONT_LAYOUT_TCOD | libtcod.FONT_TYPE_GREYSCALE)
</pre></p>
<br /><hr />
You can dynamically update the content of the font bitmap with this function :<br />
<p class="code"><pre>
C++ : static void TCODSystem::updateChar(int asciiCode, int fontx, int fonty,const TCODImage *img,int x,int y)
C   : void TCOD_sys_update_char(int asciiCode, int fontx, int fonty, TCOD_image_t img, int x, int y)
Py  : sys_update_char(asciiCode, fontx,fonty,img,x,y)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>asciiCode</td><td>Ascii code currently mapped to this font character.</td></tr>
<tr><td>fontx, fonty</td><td>Position of the character in the font (in number of characters, not in pixels)</td></tr>
<tr><td>img</td><td>New image for this character. The size of this image must be equal or greater than the font character's size.</td></tr>
<tr><td>x,y</td><td>Position of the new character bitmap in img, in pixels (in case img contains several characters).</td></tr>
</table>


